// ==================== 7. 元数据服务 ====================
package org.chen.flight.service.flight;

import org.chen.common.flight.OneWayFlightInfo;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 航班元数据服务
 * 负责航空公司、机场、城市等元数据管理
 */
@Service
public class FlightMetadataService {

    /**
     * 增强单程航班信息
     */
    public void enhanceOneWayFlightInfo(OneWayFlightInfo flight) {
        if (flight.getAirlineCode() != null) {
            flight.setAirline(getAirlineName(flight.getAirlineCode()));
        }

        if (flight.getDepartureAirportCode() != null) {
            flight.setDepartureAirport(getAirportName(flight.getDepartureAirportCode()));
        }

        if (flight.getArrivalAirportCode() != null) {
            flight.setArrivalAirport(getAirportName(flight.getArrivalAirportCode()));
        }

        if (flight.getDepartureCityCode() != null) {
            flight.setDepartureCity(getCityName(flight.getDepartureCityCode()));
        }

        if (flight.getArrivalCityCode() != null) {
            flight.setArrivalCity(getCityName(flight.getArrivalCityCode()));
        }
    }

    /**
     * 获取航空公司名称
     */
    public String getAirlineName(String airlineCode) {
        Map<String, String> airlineNames = new HashMap<>();
        airlineNames.put("MU", "东方航空");
        airlineNames.put("CA", "国航");
        airlineNames.put("CZ", "南方航空");
        airlineNames.put("HU", "海南航空");
        airlineNames.put("3U", "四川航空");
        airlineNames.put("9C", "春秋航空");
        airlineNames.put("TK", "土耳其航空");
        airlineNames.put("QR", "卡塔尔航空");
        airlineNames.put("EK", "阿联酋航空");
        airlineNames.put("SQ", "新加坡航空");
        airlineNames.put("TG", "泰国航空");

        airlineNames.put("SL", "泰国狮子航空");
        airlineNames.put("VZ", "越捷泰国航空");
        airlineNames.put("FD", "亚洲航空泰国分公司");
        airlineNames.put("ZH", "深圳航空");
        airlineNames.put("MF", "厦门航空");
        airlineNames.put("NX", "澳门航空");
        airlineNames.put("OD", "马印航空");
        airlineNames.put("CX", "国泰航空");

        return airlineNames.getOrDefault(airlineCode, airlineCode);
    }

    /**
     * 获取机场名称
     */
    public String getAirportName(String airportCode) {
        Map<String, String> airportNames = new HashMap<>();
        airportNames.put("CTU", "双流国际机场");
        airportNames.put("TFU", "天府国际机场");
        airportNames.put("PVG", "浦东国际机场");
        airportNames.put("SHA", "虹桥国际机场");
        airportNames.put("BKK", "素万那普国际机场");
        airportNames.put("DMK", "廊曼国际机场");
        airportNames.put("NRT", "成田国际机场");
        airportNames.put("HND", "羽田机场");
        airportNames.put("ICN", "仁川国际机场");
        airportNames.put("KMG", "昆明长水国际机场");

        airportNames.put("CAN", "广州白云国际机场");
        airportNames.put("SZX", "深圳宝安国际机场");
        airportNames.put("PEK", "北京首都国际机场");

        return airportNames.getOrDefault(airportCode, airportCode);
    }

    /**
     * 获取城市名称
     */
    public String getCityName(String cityCode) {
        Map<String, String> cityNames = new HashMap<>();
        cityNames.put("CTU", "成都");
        cityNames.put("SHA", "上海");
        cityNames.put("BKK", "曼谷");
        cityNames.put("NRT", "东京");
        cityNames.put("ICN", "首尔");
        cityNames.put("KMG", "昆明");

        cityNames.put("SZX", "深圳");
        cityNames.put("MFM", "澳门");
        cityNames.put("KUL", "吉隆坡");
        cityNames.put("HAK", "海口");
        cityNames.put("HKG", "香港");
        cityNames.put("BJS", "北京");
        cityNames.put("CAN", "广州");
        cityNames.put("XMN", "厦门");

        return cityNames.getOrDefault(cityCode, cityCode);
    }
}